include .env
TRINO_VERSION?=435
RELEASE_NAME?=trino
GIT_REPO?=registry.cn-hangzhou.aliyuncs.com/wenjie-base
NAMESPACE?=bi-service
export

docker_reg:
	kubectl create secret docker-registry \
		wenjie-alicloud \
    	--docker-server=registry.cn-hangzhou.aliyuncs.com \
    	--docker-username=${DOCKER_USER} \
    	--docker-password="${DOCKER_PASS}" \
  		-n ${NAMESPACE} --dry-run=client -oyaml | kubectl apply -f -

build_image:
	docker build --build-arg TRINO_VERSION=${TRINO_VERSION} \
		-t ${GIT_REPO}/trino:${TRINO_VERSION} .
	docker push ${GIT_REPO}/trino:${TRINO_VERSION}

secret:
	-kubectl delete secret trino-password-secret --namespace ${NAMESPACE}
	-rm -rf password.db
	touch password.db
	htpasswd -b -B -C 10 password.db ${TRINO_USERNAME} ${TRINO_PASSWORD}
	@file=`cat password.db`; \
		kubectl create secret generic trino-password-secret \
		--from-literal=password.db="$${file}" -n ${NAMESPACE}

template: secret
	-mkdir build
	envsubst < trino.yaml > build/trino.yaml
	helm template -f build/trino.yaml ${RELEASE_NAME} ./charts/trino -n ${NAMESPACE} > build/test.yaml

deploy: secret
	-mkdir build
	envsubst < trino.yaml > build/trino.yaml
	envsubst < config/core-site.xml > build/core-site.xml
	helm upgrade --install -f build/trino.yaml ${RELEASE_NAME} ./charts/trino -n ${NAMESPACE} \
		--set-file coordinator.additionalConfigFiles.core-site\\.xml=build/core-site.xml \
		--set-file worker.additionalConfigFiles.core-site\\.xml=build/core-site.xml \

undeploy:
	-helm uninstall ${RELEASE_NAME} -n ${NAMESPACE}